package codetop.dp;

public class Code152 {
    public int maxProduct(int[] nums) {
        int maxPro=Integer.MIN_VALUE;
        int len=nums.length;
        int dp[][]=new int[len+1][2];//dp记录最大和最小的乘积
        for (int i = 1; i <= len; i++) {
            if (nums[i-1]==0){
                dp[i][0]=0;
                dp[i][1]=0;
            }else {
                int product1=nums[i-1];
                int product2=dp[i-1][0];
                int product3=dp[i-1][1];
                int max=Math.max(product1,Math.max(product1*product2,product1*product3));
                int min=Math.min(product1,Math.min(product1*product2,product1*product3));
                dp[i][1]=min;
                dp[i][0]=max;
            }
            maxPro=Math.max(dp[i][0],maxPro);

        }
        return maxPro;
    }
}
